package com.gjun.struts.action;

import java.util.List;

import org.omg.PortableInterceptor.SUCCESSFUL;

import com.gjun.struts.bean.GjunsystemPrivilege;
import com.gjun.struts.resource.GjunPrivilegeResourceIf;
import com.gjun.struts.util.JSONHelper;

public class PrivilegeRootInitAction {
	private GjunPrivilegeResourceIf privilegeDAO;

	private String result;

	private String pid;

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public GjunPrivilegeResourceIf getPrivilegeDAO() {
		return privilegeDAO;
	}

	public void setPrivilegeDAO(GjunPrivilegeResourceIf privilegeDAO) {
		this.privilegeDAO = privilegeDAO;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String loadRoot() {
        
		List<GjunsystemPrivilege> list = privilegeDAO.loadAllRootPrivilege(); // 获取所有的一级节点对象
		
		System.out.println("privilege"+list);
		try {
			result = JSONHelper.prisToJson(list);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println("result:  " + result);
		return "success";
	}
	public String loadChilds() {
        if(pid==null){
        	result = "";
        	return "success";
        }
		List<GjunsystemPrivilege> list = privilegeDAO.loadChildPrivilegeByPID(Integer.parseInt(pid));
		try {
			result = JSONHelper.prisToJson(list);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println("result:  " + result);
		return "success";
	}
}
